//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "adminActions\fn_ui_moderation_repair.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_isAdmin","_dialog","_vehicle","_selected_index","_crew"];
PARAMS_2(_selected_index,_vehicle);
if (GVAR(AdminCmds) == 1) then { 
	if (isnil "_vehicle" || {isnull _vehicle}) exitWith { hint localize "STR_MSO_AA_NOVECSELECTION"; };
	_isAdmin = (call mso_fnc_isAdmin);
	if (!isnil "mp_rights_fnc_isAdmin") then {
		_isAdmin = _isAdmin || ([] call mp_rights_fnc_isAdmin) || ([] call mp_rights_fnc_isModerator);
	};
	if (_isAdmin) then {
		if (damage _vehicle > 0.7) exitWith { hint localize "STR_MSO_AA_TOOMUCHDAMAGE"; };
		waituntil {!dialog || !alive player};
		if (alive player) then {
			_crew = crew _vehicle;
			GVAR(ui_moderation_confirm) = [true,"repair",_vehicle, vehicleVarName _vehicle, _crew];
			if (!isnil QGVAR(ui_moderation_confirm)
				&& {typename GVAR(ui_moderation_confirm) == typename []}
				&& {count GVAR(ui_moderation_confirm) > 0}) then {
				if (GVAR(ui_moderation_confirm) select 0) then {
					[QGVAR(REPAIR),[GVAR(ui_moderation_confirm),name player,getPlayerUID player]] call FUNC(raiseEvent);
				};
			} else {
				TRACE_1("failed confirm",GVAR(ui_moderation_confirm));
			};
		};
	} else {
		hint localize "STR_MSO_AA_CMD_NA";
	};	
};

TRACE("End");
TMFPROFILERSTOP;
